package components;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Created by IntelliJ IDEA.
 * User: Zlobec
 * Date: 02.03.2006
 * Time: 11:47:36
 * To change this template use File | Settings | File Templates.
 */
public class JChangeCardDialog extends JCardDialog implements ActionListener
{
    private WMLEditorApplet wmlEditor;

    public JChangeCardDialog(WMLEditorApplet wmlEditor)
    {
         super(wmlEditor);
        this.wmlEditor = wmlEditor;
        WMLEditorPane selectedWmlPane = getSelectedWmlPane();
        cardID.setText(selectedWmlPane.getCardID());
        cardName.setText(selectedWmlPane.getCardTitle());


    }

    private WMLEditorPane getSelectedWmlPane() {
        JScrollPane selectedScrollPane = (JScrollPane) wmlEditor.tabbedPane.getSelectedComponent();
        return (WMLEditorPane) selectedScrollPane.getViewport().getView();
    }

    public void actionPerformed(ActionEvent e) {
      if (e.getActionCommand().equalsIgnoreCase("dialogCancel")) {

          this.dispose();
      }
      if (e.getActionCommand().equalsIgnoreCase("dialogOK")) {
          WMLEditorPane selectedWmlPane = getSelectedWmlPane();
          selectedWmlPane.setCardID(cardID.getText());
          selectedWmlPane.setCardTitle(cardName.getText());
          wmlEditor.tabbedPane.setTitleAt(wmlEditor.tabbedPane.getSelectedIndex(),cardID.getText()+":"+cardName.getText());
          this.dispose();
          }
      }

    }
